
import cloud from '@lafjs/cloud'
const db = cloud.database()
const _ = db.command
import nw from "nw-lafjs";
import {fail, ok} from "@/utils/responseUtil";
export default async function (ctx: FunctionContext) {
  let body = ctx.body
  /**
   * {
   *    "_id":"dsdd",
   *   "username": "wuzuxian",
   *   "password": "wzxwsq1314",
   *   "name": "吴祖贤",
   * }
   */

  //1。数据校验
  if (nw.util.isNull(body._id)){
    return fail("数据不合法")
  }

  let dataJson = {
    username:body.username,
    password:body.password,
    name:body.name
  }
  //2.修改数据即可
  let num = await nw.db.update({
    dbName:"admin",
    whereJson:{
      _id:_.eq(body._id)
    },
    dataJson:dataJson
  })

  if (num<=0){
    return fail("修改失败")
  }
  return  ok("修改成功")
}
